// $Id: track.h 113 2011-11-28 17:07:05Z cedric.shih@gmail.com $
/*
 * Copyright 2011 Cedric Shih (cedric dot shih at gmail dot com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef TRACK_H_
#define TRACK_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <niohttp/server.h>

#include "listener.h"

struct niohttp_media;

struct niohttp_track {
	struct niohttp_media *media;
	char *name;
	char *type;
	struct niohttp_listener_list listeners;
	char *sdp_attrs;
	niohttp_track_describe_cb describe;
	niohttp_track_cb setup;
	niohttp_track_cb teardown;
	niohttp_track_cb refresh;
	niohttp_track_finalize_cb finalize;
	void *cbarg;
	int init;
	TAILQ_ENTRY(niohttp_track) entry;
};

int niohttp_track_describe(struct niohttp_track *track,
		struct niohttp_headers *headers);

int niohttp_track_setup(struct niohttp_track *track);

int niohttp_track_teardown(struct niohttp_track *track);

int niohttp_track_refresh(struct niohttp_track *track);

int niohttp_track_listen(struct niohttp_track *track,
		niohttp_data_cb cb, void *cbarg);

int niohttp_track_unlisten(struct niohttp_track *track,
		niohttp_data_cb cb, void *cbarg);

int niohttp_track_push(struct niohttp_track *track, struct timeval *timestamp,
		struct zcbuffer *buffer);

TAILQ_HEAD(niohttp_track_list, niohttp_track);

int niohttp_track_list_add(struct niohttp_track_list *list, const char *name,
		const char *type, struct niohttp_track **track);

void niohttp_track_list_del(struct niohttp_track_list *list,
		struct niohttp_track *track);

struct niohttp_track *niohttp_track_list_find(struct niohttp_track_list *list,
		const char *name);

void niohttp_track_list_clear(struct niohttp_track_list *list);

#ifdef __cplusplus
}
#endif

#endif /* TRACK_H_ */
